package com.jfeat.am.module.wegou.api.patch;

import com.jfeat.am.common.constant.tips.ErrorTip;
import com.jfeat.am.common.constant.tips.SuccessTip;
import com.jfeat.am.common.constant.tips.Tip;
import com.jfeat.am.common.exception.BizExceptionEnum;
import com.jfeat.am.common.exception.BusinessException;
import com.jfeat.am.core.util.Convert;
import com.jfeat.am.module.systemconfig.services.crud.service.SystemConfigService;
import com.jfeat.am.module.systemconfig.services.persistence.model.SystemConfig;
import com.jfeat.am.module.wegou.exception.WegouBizException;
import com.jfeat.am.module.wegou.services.patch.DealExchangeRateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by Silent-Y on 2018/2/24.
 */
@Api("获取汇率")
@RestController
@RequestMapping("/api")
public class ExchangeRateEndpoint {

    @Resource
    DealExchangeRateService dealExchangeRateService;

    @ApiOperation(value = "人民币日元汇率",response = Integer.class)
    @GetMapping("/exchangerate/{key}")
    public Tip getExchangeRateByKey(@PathVariable String key){
        SystemConfig systemConfig = dealExchangeRateService.getSystemConfigByKey(key);
        if (systemConfig == null){
            return ErrorTip.create(WegouBizException.GET_EXCHANGE_RATE_FAILED.getCode(),WegouBizException.GET_EXCHANGE_RATE_FAILED.getMessage());
        }
        return SuccessTip.create(systemConfig.getDataValue().toString());
    }
}
